<?php

// 上传商业计划书
// POST bp.upload

namespace app\api\resource\bp;
use think\Db;
use think\Session;

class Upload
{
    // 方法
    public $_method = ['POST'];
    // 前置
    public $_pre    = ['login','isCyz'];
    // 描述
    public $_description = '上传商业计划书';
    // 参数
    public $_param  = [
        'title'  => '名称',
        'bp_uri' => '商业计划书URI',
    ];
    // 返回
    public $_return = [
        201 => '上传成功',
        422 => '商业计划书必须',
        500 => '服务器错误',
    ];

    public function run(&$request)
    {
        $title = $request->post('title/s',date('YmdHis'),'trim');
        $bpUri = $request->post('bp_uri/s','','trim');

        if ( empty($bpUri) ) return [422,'商业计划书必须'];

        $data['member_id']   = Session::get('member.id');
        $data['title']       = $title;
        $data['bp_uri']      = $bpUri;
        $data['create_time'] = time();
        $num =Db::name('bp')->insert($data);

        return ($num > 0) ? [201,$data] : 500;
    }
}